project(jmi)
cmake_minimum_required(VERSION 3.0)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

if(POLICY CMP0063) # visibility. since 3.3
  cmake_policy(SET CMP0063 NEW)
endif()
set(CMAKE_CXX_VISIBILITY_PRESET hidden) #use with -fdata-sections -ffunction-sections to reduce target size
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FindJava)
find_package(Java COMPONENTS Development REQUIRED)
include(UseJava)

message("java=${Java_JAVA_EXECUTABLE}")
message("javac=${Java_JAVAC_EXECUTABLE}")
if(ANDROID)
else()
  include(FindJNI)
  find_package(JNI REQUIRED)
  include_directories(${JNI_INCLUDE_DIRS})
  enable_testing()
endif()
include_directories(${CMAKE_SOURCE_DIR})
add_library(jmi STATIC jmi.cpp)
add_executable(test_signature test/signature.cpp)
target_link_libraries(test_signature LINK_PRIVATE jmi)
add_library(JMITest SHARED test/JMITest.cpp)
target_link_libraries(JMITest LINK_PRIVATE jmi)
add_jar(test_jmi test/JMITest.java)
get_target_property(jar_path test_jmi JAR_FILE)
get_target_property(class_dir test_jmi CLASSDIR)
message(STATUS "Jar file: ${jar_path}")
message(STATUS "Class compiled to: ${class_dir}")
#add_test(NAME signature_test COMMAND )
add_test(NAME jmitest COMMAND ${Java_JAVA_EXECUTABLE} -cp ${jar_path} JMITest)
if(ANDROID)
  target_link_libraries(test_signature LINK_PRIVATE -landroid -llog)
  target_link_libraries(JMITest LINK_PRIVATE -landroid -llog)
endif()
